import Vue from "vue";
import VueRouter from "vue-router";
import Home from "../views/Home.vue";
import ViewUI from "view-design";
//import 'view-design/dist/styles/iview.css';

Vue.use(ViewUI);

Vue.use(VueRouter);

const routes = [
  {
    path: "/",
    name: "Home",
    component: () => import("../views/Home.vue"),
    meta: {
      istext: true,
      title: "首页",
      path: "/",
    },
    redirect: "/index",
    children: [
      {
        path: "/index",
        name: "index",
        component: () => import("../views/Index/Index.vue"),
        meta: { title: "首页", path: "/index", bread: "/index" },
      },
      {
        path: "/ShopTube",
        name: "ShopTube",
        component: () => import("../views/ShopTube.vue"),
        meta: { title: "商品管理", path: "/ShopTube", bread: "/ShopTube" },
      },

      {
        path: "/TubeAdd",
        name: "TubeAdd",
        component: () => import("../views/TubeAdd.vue"),
        meta: { title: "商品添加", path: "/TubeAdd", bread: "/TubeAdd" },
      },

      {
        path: "/usermanage",
        name: "usermanage",
        component: () => import("../views/user/usermanage.vue"),
        meta: { title: "用户管理", path: "/usermanage" },
      },
      {
        path: "/usergroup",
        name: "usergroup",
        component: () => import("../views/user/usergroup.vue"),
        meta: { title: "用户分组", path: "/usergroup", bread: "/usergroup" },
      },
      {
        path: "/userlabel",
        name: "userlabel",
        component: () => import("../views/user/userlabel.vue"),
        meta: { title: "用户标签", path: "/userlabel", bread: "/userlabel" },
      },
      {
        path: "/shop_classify",
        name: "Classify",
        component: () => import("../views/Classify.vue"),
        meta: {
          title: "商品分类",
          path: "/shop_classify",
          bread: "/shop_classify",
        },
      },
      {
        path: "/MemberClass",
        name: "MemberClass",
        component: () => import("../views/MemberClass.vue"),
        meta: {
          title: "会员等级",
          path: "/MemberClass",
          bread: "/MemberClass",
        },
      },
      {
        path: "/product",
        name: "product",
        component: () => import("../views/ProductReviews/product.vue"),
        meta: { title: "商品评论", path: "/product", bread: "/product" },
      },
      {
        path: "/MoneyRecord",
        name: "MoneyRecord",
        component: () => import("../views/MoneyRecord.vue"),
        meta: {
          title: "资金记录",
          path: "/MoneyRecord",
          bread: "/MoneyRecord",
        },
      },
      {
        path: "/CommissionRecord",
        name: "CommissionRecord",
        component: () => import("../views/CommissionRecord.vue"),
        meta: { title: "佣金记录", path: "/CommissionRecord" },
      },
      {
        path: "/AdministratorList",
        name: "AdministratorList",
        component: () => import("../views/AdministratorList.vue"),
        meta: {
          title: "管理员列表",
          path: "/AdministratorList",
          bread: "/AdministratorList",
        },
      },
      {
        path: "/SignIn",
        name: "SignIn",
        component: () => import("../views/data allocation/SignIn.vue"),
        meta: { title: "签到天数配置", path: "/SignIn", bread: "/SignIn" },
      },
      {
        path: "/OrderDetails",
        name: "OrderDetails",
        component: () => import("../views/data allocation/OrderDetails.vue"),
        meta: {
          title: "订单详情动态图",
          path: "/OrderDetails",
          bread: "/OrderDetails",
        },
      },
      {
        path: "/PersonalCenter",
        name: "PersonalCenter",
        component: () => import("../views/data allocation/PersonalCenter.vue"),
        meta: {
          title: "个人中心菜单",
          path: "/PersonalCenter",
          bread: "/PersonalCenter",
        },
      },
      {
        path: "/HotList",
        name: "HotList",
        component: () => import("../views/data allocation/HotList.vue"),
        meta: { title: "热门榜单推荐", path: "/HotList", bread: "/HotList" },
      },
      {
        path: "/NewProducts",
        name: "NewProducts",
        component: () => import("../views/data allocation/NewProducts.vue"),
        meta: {
          title: "首发新品推荐",
          path: "/NewProducts",
          bread: "/NewProducts",
        },
      },
      {
        path: "/PromotionItem",
        name: "PromotionItem",
        component: () => import("../views/data allocation/PromotionItem.vue"),
        meta: {
          title: "促销单品推荐",
          path: "/PromotionItem",
          bread: "/PromotionItem",
        },
      },
      {
        path: "/Distribution",
        name: "Distribution",
        component: () => import("../views/data allocation/Distribution.vue"),
        meta: { title: "个人中心分销海报", path: "/Distribution"  ,bread:'/Distribution'},
      },
      {
        path: "/Recommendation",
        name: "Recommendation",
        component: () => import("../views/data allocation/Recommendation.vue"),
        meta: { title: "精品推荐", path: "/Recommendation"  ,bread:'/Recommendation'},
      },
      {
        path: "/DiscountsTemplate",
        name: "DiscountsTemplate",
        component: () => import("../views/data allocation/DiscountsTemplate.vue"),
        meta: { title: "优惠券模板", path: "/DiscountsTemplate"  ,bread:'/DiscountsTemplate'},
      },
      {
        path: "/specification",
        name: "specification",
        component: () => import("../views/specification/specification.vue"),
        meta: {
          title: "商品规格",
          path: "/specification",
          bread: "/specification",
        },
      },
      {
        path: "/order",
        name: "order",
        component: () => import("../views/order/order.vue"),
        meta: { title: "订单", path: "/order", bread: "/order" },
      },
      {
        path: "/discount",
        name: "Discount",
        component: () => import("../views/Discount/Discount.vue"),
        meta: {
          title: "优惠券列表",
          path: "/discount",
          bread: "/discount",
          keepAlive: true,
        },
      },
      {
        path: "/history",
        name: "History",
        component: () => import("../views/Discount/History.vue"),
        meta: { title: "用户领取记录", path: "/history", bread: "/history" },
      },
      {
        path: "/books",
        name: "books",
        component: () => import("../views/books/books.vue"),
        meta: { title: "文章管理", path: "/books", bread: "/books" },
        redirect: "/writer",
        children: [
          {
            path: "/writer",
            name: "writer",
            component: () => import("../views/books/writer.vue"),
            meta: { title: "文章管理", path: "/writer", bread: "/writer" },
          },
          {
            path: "/addbooks",
            name: "addbooks",
            component: () => import("../views/books/addbooks.vue"),
            meta: { title: "添加文章", path: "/addbooks", bread: "/addbooks" },
          },
        ],
      },
      {
        path: "/Categories",
        name: "Categories",
        component: () => import("../views/books/Categories.vue"),
        meta: { title: "文章分类", path: "/Categories" },
      },
      {
        path: "/city",
        name: "City",
        component: () => import("../views/Logistics/City.vue"),
        meta: { title: "城市数据", path: "/city" },
      },
      {
        path: "/company",
        name: "Company",
        component: () => import("../views/Logistics/Company.vue"),
        meta: { title: "物流公司", path: "/company" },
      },
      {
        path: "/pickuper",
        name: "pickuper",
        component: () => import("../views/pickup/pickuper.vue"),
        meta: { title: "提货点", path: "/pickuper" },
      },
      {
        path: "/verifier",
        name: "verifier",
        component: () => import("../views/pickup/verifier.vue"),
        meta: { title: "核销员", path: "/verifier" },
      },
      {
        path:"/rechargerecord",
        name:"rechargerecord",
        component: () => import("../views/finance/rechargerecord.vue"),
        meta: { title: "充值记录", path: "/rechargerecord" },
      },
      {
        path: "/vxtemplate",
        name: "vxtemplate",
        component: () => import("../views/adhibition/vxtemplate.vue"),
        meta: { title: "微信消息模板", path: "/vxtemplate" },
      },
      {
        path:"/attention",
        name:'attention',
        component:()=>import('../views/adhibition/autoresponse/attention.vue'),
        meta: { title: "微信关注回复", path: "/attention" },
      },
      {
        path:"/invalid",
        name:'invalid',
        component:()=>import('../views/adhibition/autoresponse/invalid.vue'),
        meta: { title: "无效关键字回复", path: "/invalid" },
      },
      {
        path:"/chu",
        name:'chu',
        component:()=>import('../views/adhibition/chu.vue'),
        meta: { title: "自动回复", path: "/chu" },
        children:[
          {
            path:"/keyword",
            name:'keyword',
            component:()=>import('../views/adhibition/autoresponse/keyword.vue'),
            meta: { title: "关键字回复", path: "/keyword" },
              
          },
          {
            path:"/keyword/keyAdd",
            name:'/keyword/keyAdd',
            component:()=>import('../views/adhibition/autoresponse/keyAdd.vue'),
            meta: { title: "关键字添加", path: "/keyword/keyAdd" },
          },
        ]
      },
      {
        path: "/maintain",
        name: "maintain",
        component: () => import("../views/Maintain/index.vue"),
        redirect: "/maintain/classify",
        meta: { title: "开发配置", path: "/maintain" },
        children: [
          {
            path: "/maintain/classify",
            name: "Maintain",
            component: () => import("../views/Maintain/classify.vue"),
            meta: { title: "配置分类", path: "/kaifa/maintain" },
          },
          {
            path: "/maintain/data",
            name: "Maintain",
            component: () => import("../views/Maintain/data.vue"),
            meta: { title: "组合数据", path: "/maintain/data" },
          },
        ],
      },
    ],
  },

  {
    path: "/about",
    name: "About",
    component: () => import("../views/About.vue"),
  },
  {
    path: "/login",
    name: "Login",
    component: () => import("../views/Login.vue"),
  },
];

const router = new VueRouter({
  mode: "history",
  routes,
});
router.beforeEach((to, from, next) => {
  if (
    to.matched.some((v) => {
      return v.meta.istext === true;
    })
  ) {
    if (localStorage.getItem("token")) {
      ViewUI.LoadingBar.start();
      next();
    } else {
      next("/login");
    }
  } else {
    ViewUI.LoadingBar.start();
    next();
  }
});

router.afterEach((route) => {
  ViewUI.LoadingBar.finish();
});

export default router;
